package com.hf.bill

import com.hf.constant.OrderLunchConst
import com.hf.date.DateUtils
import com.hf.mail.AbstractMailService
import com.hf.mail.MailMessage
import com.hf.order.OrderPeriodService
import com.hf.order.UserOrderHistoryService
import com.hf.template.GspTemplateUtils

class MailBillOfMonthAdminService extends AbstractMailService {

	UserOrderHistoryService userOrderHistoryService
	UserBillPeriodHistoryService userBillPeriodHistoryService
	OrderPeriodService orderPeriodService

	void sendMail() {
		List<Date> periodStartEndDay = DateUtils.getPeriodStartEndDay()
		int totalCount = userOrderHistoryService.getOrderMonthCount(periodStartEndDay)
		List orderMonthCountList = userOrderHistoryService.getOrderMonthCountList(periodStartEndDay)
		send(orderMonthCountList, totalCount)
	}

	private void send(List orderMonthCountList, int totalCount) {
		MailMessage mail = new MailMessage()
		mail.to = [OrderLunchConst.ADMIN_EMAIL]

		mail.subject = OrderLunchConst.FROM_ORDER_LUNCH + "This month bill info  Month:" + DateUtils.todayJoda.monthOfYear
		mail.htmlText = GspTemplateUtils.renderTemplate('/bill/emailAdminMonthBill', [orderMonthCountList : orderMonthCountList, totalCount : totalCount])

		mailSenderService.sendAsyn(mail)
	}
}
